package com.tedu.project5.controller;


import com.tedu.project5.common.Result;
import com.tedu.project5.dto.PurchaseInfoDTO;
import com.tedu.project5.dto.QueryPurchaseInfoDTO;
import com.tedu.project5.model.DdPurchaseInfo;
import com.tedu.project5.service.IDdPurchaseInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 采购表 前端控制器
 * </p>
 *
 * @author mhg
 * @since 2022-06-20
 */
@Slf4j
@RestController
@RequestMapping("/project5/ddPurchaseInfo")
public class DdPurchaseInfoController {

    @Autowired
    private IDdPurchaseInfoService iDdPurchaseInfoService;

    /**
     * 查询采购列表
     * @return
     * http://localhost:9999/project5/ddPurchaseInfo/listAll
     */
    @CrossOrigin
    @PostMapping("/listAll")   //南宁市
    public Result list(@RequestBody QueryPurchaseInfoDTO dto){
        log.info("参数值--:"+ dto);
        return iDdPurchaseInfoService.queryExample(dto);
    }

    /**
     * 新增采购
     * @param purchaseInfo
     * @return
     */
    @CrossOrigin
    @PostMapping("/addPurchaseInfo")
    public Result addUser(@RequestBody DdPurchaseInfo purchaseInfo){
        log.info("参数值--："+ purchaseInfo);
        return iDdPurchaseInfoService.savePurchase(purchaseInfo);
    }

    /**
     * 更新采购信息
     * @param dto
     * @return
     */
    @CrossOrigin
    @PostMapping("/updateById")
    public Result updateById(@RequestBody PurchaseInfoDTO dto){
        log.info("参数值--："+ dto);
        return iDdPurchaseInfoService.updatePurchase(dto);
    }

    /**
     * 删除采购信息
     * @param id
     * @return
     */
    @CrossOrigin
    @PostMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable String id){
        log.info("参数值id--："+ id);
        return iDdPurchaseInfoService.deletePurchase(id);
    }
    

}
